export default (initialState: API.UserInfo) => {
  // 检查用户是否已登录
  const isLoggedIn = () => {
    const token = localStorage.getItem('token');
    const user = localStorage.getItem('user');
    return !!(token && user);
  };

  // 获取当前用户信息
  const getCurrentUser = () => {
    try {
      const userStr = localStorage.getItem('user');
      return userStr ? JSON.parse(userStr) : null;
    } catch {
      return null;
    }
  };

  const currentUser = getCurrentUser();
  const loggedIn = isLoggedIn();

  // 权限定义
  const canSeeAdmin = !!(currentUser && currentUser.role === 'admin');
  const canAccessApp = loggedIn;

  return {
    canSeeAdmin,
    canAccessApp,
    isLoggedIn: loggedIn,
    currentUser,
  };
};
